#!/usr/bin/python3
# -*- coding:utf-8 -*-
# __author__ == taoyulong2018@gmail.com
# __time__ == 2023/8/21 14:51
# ===========================================
#       题目名称： 17. 电话号码的字母组合
#       题目地址： https://leetcode.cn/problems/letter-combinations-of-a-phone-number/description/
#       题目描述： https://note.youdao.com/s/RRXNSXjR
# ===========================================


class Solution:
    """
        实现思路：
            定义一个字典，将按键出现的字符串初始化
            然后遍历循环
    """

    def letterCombinations(self, digits):
        res = []  # 返回值
        if not digits:  # 处理为0个的时候
            return res
        phone_number_letters_dict = {
            "1": [], "2": ["a", "b", "c"], "3": ["d", "e", "f"],
            "4": ["g", "h", "i"], "5": ["j", "k", "l"], "6": ["m", "n", "o"],
            "7": ["p", "q", "r", "s"], "8": ["t", "u", "v"], "9": ["w", "x", "y", "z"],
            "*": [], "0": [], "#": [],
        }  # 定义电话数字对应字符串
        cur_index = 0  # 当前下标
        while cur_index < len(digits):
            digit = digits[cur_index]
            phone_number_letters = phone_number_letters_dict[digit]
            if res:
                temp_res = []
                for res_letter in res:
                    for digit_letter in phone_number_letters:
                        temp_res.append(res_letter + digit_letter)
                res = temp_res
            else:
                res = phone_number_letters
            cur_index += 1
        return res


if __name__ == '__main__':
    s = Solution()
    # ["ad","ae","af","bd","be","bf","cd","ce","cf"]
    print(s.letterCombinations(digits="23"))
    # ""
    print(s.letterCombinations(digits=""))
    # ["a","b","c"]
    print(s.letterCombinations(digits="2"))
